# 需求：爬取搜狗首页的页面数据
import requests
if __name__ == "__main__":
    # step 1：指定url
    headers ={
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42'

    }
    url = 'https://www.zhihu.com/'
    # step 2：发起请求
    # get方法返回一个响应对新
    response = requests.get(url=url, headers=headers)
    # step 3：获取响应数据
    page_text=response.text
    print(page_text)
    # step 4：持久化存储
    with open('./zhihu.html', 'w', encoding='utf-8') as fp:
        fp.write(page_text)
    print('爬取完成!!!')